// #ifdef APP-PLUS
const permissionsModule = uni.requireNativePlugin('Chen-PermissionsPlugin')
// #endif

export function checkPermissions(permission) {
  /* #ifdef APP-PLUS */
  if (permission === 'album') {
    permission = 'photo'
  }
  permissionsModule.checkPermissions(permission, (result) => {
    return result
  })
  /* #endif */
  /* #ifdef MP-WEIXIN */
  const appAuthorizeSetting = uni.getAppAuthorizeSetting()
  const authorizeResult = appAuthorizeSetting[permission + 'Authorized']
  if (authorizeResult === 'authorized' || authorizeResult === 'non determined') {
    return true
  } else if (authorizeResult === 'denied') {
    uni.openAppAuthorizeSetting()
    return false
  } else {
    return false
  }
  /* #endif */
}
